Store host dylib path in compilation
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 13 Oct 2016 16:30:59 +0000 (19:30 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 13 Oct 2016 16:30:59 +0000 (19:30 +0300)
src/cargo/ops/cargo_rustc/compilation.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/custom_build.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/ops/cargo_test.rs

index 88a935247f5ee30e1f20a6a0e9e9aa2239d2a68d..89dfd12daa2adf26f349fd0888ade91447397f18 100644 (file)
@@ -1,6 +1,6 @@
 use std::collections::{HashMap, HashSet};
 use std::ffi::OsStr;
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
 use semver::Version;
 
 use core::{PackageId, Package, Target};
@@ -33,6 +33,10 @@ pub struct Compilation<'cfg> {
     /// Output directory for rust dependencies
     pub deps_output: PathBuf,
 
+    /// Library search path for compiler plugins and build scripts
+    /// which have dynamic dependencies.
+    pub plugins_dylib_path: PathBuf,
+
     /// Extra environment variables that were passed to compilations and should
     /// be passed to future invocations of programs.
     pub extra_env: HashMap<PackageId, Vec<(String, String)>>,
@@ -54,6 +58,7 @@ impl<'cfg> Compilation<'cfg> {
             native_dirs: HashSet::new(),  // TODO: deprecated, remove
             root_output: PathBuf::from("/"),
             deps_output: PathBuf::from("/"),
+            plugins_dylib_path: PathBuf::from("/"),
             tests: Vec::new(),
             binaries: Vec::new(),
             extra_env: HashMap::new(),
@@ -65,27 +70,25 @@ impl<'cfg> Compilation<'cfg> {
     }
 
     /// See `process`.
-    pub fn rustc_process(&self, pkg: &Package, host_dylib_path: &Path)
-                         -> CargoResult<ProcessBuilder> {
-        self.fill_env(try!(self.config.rustc()).process(), pkg, Some(host_dylib_path))
+    pub fn rustc_process(&self, pkg: &Package) -> CargoResult<ProcessBuilder> {
+        self.fill_env(try!(self.config.rustc()).process(), pkg, true)
     }
 
     /// See `process`.
-    pub fn rustdoc_process(&self, pkg: &Package, host_dylib_path: Option<&Path>)
-                           -> CargoResult<ProcessBuilder> {
-        self.fill_env(process(&*try!(self.config.rustdoc())), pkg, host_dylib_path)
+    pub fn rustdoc_process(&self, pkg: &Package) -> CargoResult<ProcessBuilder> {
+        self.fill_env(process(&*try!(self.config.rustdoc())), pkg, true)
     }
 
     /// See `process`.
-    pub fn target_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
-                                           -> CargoResult<ProcessBuilder> {
-        self.fill_env(process(cmd), pkg, None)
+    pub fn host_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
+                                         -> CargoResult<ProcessBuilder> {
+        self.fill_env(process(cmd), pkg, true)
     }
 
     /// See `process`.
-    pub fn host_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package, host_dylib_path: &Path)
-                                         -> CargoResult<ProcessBuilder> {
-        self.fill_env(process(cmd), pkg, Some(host_dylib_path))
+    pub fn target_process<T: AsRef<OsStr>>(&self, cmd: T, pkg: &Package)
+                                           -> CargoResult<ProcessBuilder> {
+        self.fill_env(process(cmd), pkg, false)
     }
 
     /// Prepares a new process with an appropriate environment to run against
@@ -93,13 +96,11 @@ impl<'cfg> Compilation<'cfg> {
     ///
     /// The package argument is also used to configure environment variables as
     /// well as the working directory of the child process.
-    fn fill_env(&self, mut cmd: ProcessBuilder, pkg: &Package, host_dylib_path: Option<&Path>)
+    fn fill_env(&self, mut cmd: ProcessBuilder, pkg: &Package, is_host: bool)
                 -> CargoResult<ProcessBuilder> {
 
-        let mut search_path = if let Some(host_dylib_path) = host_dylib_path {
-            // When invoking a tool, we need the *host* deps directory in the dynamic
-            // library search path for plugins and such which have dynamic dependencies.
-            vec![host_dylib_path.to_path_buf()]
+        let mut search_path = if is_host {
+            vec![self.plugins_dylib_path.clone()]
         } else {
             let mut search_path = vec![];
 
index e7f57fe57d23038bdc90168a7ab899c6de5ff9cf..59aa170212c31b6b48d95e33074ed24ca8a6f417 100644 (file)
@@ -110,6 +110,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             None => {}
         }
 
+        self.compilation.plugins_dylib_path = self.host.deps().to_path_buf();
+
         let layout = self.target.as_ref().unwrap_or(&self.host);
         self.compilation.root_output = layout.dest().to_path_buf();
         self.compilation.deps_output = layout.deps().to_path_buf();
@@ -280,11 +282,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         }
     }
 
-    /// Returns the path for plugin/dylib dependencies
-    pub fn host_dylib_path(&self) -> &Path {
-        self.host.deps()
-    }
-
     /// Returns the appropriate output directory for the specified package and
     /// target.
     pub fn out_dir(&self, unit: &Unit) -> PathBuf {
index bca5d018d11ae2308d10cc93dbbc2bb25ce5b3d0..6a324a378a1a46351b7279faabd5546a6c6e7ff2 100644 (file)
@@ -97,7 +97,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
     // package's library profile.
     let profile = cx.lib_profile(unit.pkg.package_id());
     let to_exec = to_exec.into_os_string();
-    let mut cmd = try!(cx.compilation.host_process(to_exec, unit.pkg, cx.host_dylib_path()));
+    let mut cmd = try!(cx.compilation.host_process(to_exec, unit.pkg));
     cmd.env("OUT_DIR", &build_output)
        .env("CARGO_MANIFEST_DIR", unit.pkg.root())
        .env("NUM_JOBS", &cx.jobs().to_string())
index 459fb81dd1b63386971c2d2b5c6a93d2d269b4b3..33f86c0ef1bfa5570726b248d10686e9ef54edc1 100644 (file)
@@ -415,7 +415,7 @@ fn add_plugin_deps(rustc: &mut ProcessBuilder,
 fn prepare_rustc(cx: &Context,
                  crate_types: Vec<&str>,
                  unit: &Unit) -> CargoResult<ProcessBuilder> {
-    let mut base = try!(cx.compilation.rustc_process(unit.pkg, cx.host_dylib_path()));
+    let mut base = try!(cx.compilation.rustc_process(unit.pkg));
     build_base_args(cx, &mut base, unit, &crate_types);
     build_plugin_args(&mut base, cx, unit);
     try!(build_deps_args(&mut base, cx, unit));
@@ -424,7 +424,7 @@ fn prepare_rustc(cx: &Context,
 
 
 fn rustdoc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
-    let mut rustdoc = try!(cx.compilation.rustdoc_process(unit.pkg, Some(cx.host_dylib_path())));
+    let mut rustdoc = try!(cx.compilation.rustdoc_process(unit.pkg));
     rustdoc.arg(&root_path(cx, unit))
            .cwd(cx.config.cwd())
            .arg("--crate-name").arg(&unit.target.crate_name());
index aa4a23ba02b2a0c7c74aa79a3ea6ac5f4ae5178e..71a22d4e46178f8aba847d6dccd8a4e9b666aaef 100644 (file)
@@ -128,7 +128,7 @@ fn run_doc_tests(options: &TestOptions,
     for (package, tests) in libs {
         for (lib, name, crate_name) in tests {
             try!(config.shell().status("Doc-tests", name));
-            let mut p = try!(compilation.rustdoc_process(package, None));
+            let mut p = try!(compilation.rustdoc_process(package));
             p.arg("--test").arg(lib)
              .arg("--crate-name").arg(&crate_name);